import React from "react";
/* 1. 引入 createContext useContext */
import { createContext, useContext } from "react";
/* 2. 创建上下文 */
let context = createContext(null);
const Child = () => {
  // 4. 获取共享值
  let value = useContext(context);
  return (
    // <div>
    //   <h1>Child 组件: {value}</h1>
    // </div>
    <context.Consumer>
      {(value) => <h1>Child 组件: {value}</h1>}
    </context.Consumer>
  );
};

const App = () => {
  return (
    <div>
      {/* 3. 使用 Provider 值的共享，value=共享数据 */}
      <context.Provider value="小坏蛋！！">
        <Child></Child>
      </context.Provider>
    </div>
  );
};

export default App;
